<?php

namespace app\admin\model;

use think\Model;

class Admin extends Model
{
    public function checkAdmin($user_name,$password){
    	 $user=$this->where('username',$user_name)->find();

    	  if(!$user){
    	  	return ['status'=>'fail','mag'=>'用户名不存在'];
    	  }
    	  $pass=md5($password.$user['salt']);
    	  if($pass==$user['password_hash']){
    	  	return ['status'=>'success','msg'=>'登陆成功'];
    	  }else{
    	  	return ['status'=>'fail','msg'=>'密码不正确'];
    	  }
    }

    //用户注册插入数据库
    public function insertUser($data){
        return $this->insert($data);
    }
    //管理员列表
    public function adminList(){
        $res=$this->find()->field(['id','username','type','realname','created_at'])->paginate(20);
        return $res;
    }
    //删除管理员
    public function deleteAdmin($id){
         return $this->where('id',$id)->delete();
    }

}
